package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.cdp.pboc.service.facade.BdZxInfoService;
import com.irdstudio.cdp.pboc.service.dao.BdZxInfoDao;
import com.irdstudio.cdp.pboc.service.domain.BdZxInfo;
import com.irdstudio.cdp.pboc.service.vo.BdZxInfoVO;


/**
 * Service Impl: 百度征信信息表服务实现
 * @author ligm
 * @date 2019-07-10 
 */
@Service("bdZxInfoService")
public class BdZxInfoServiceImpl implements BdZxInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(BdZxInfoServiceImpl.class);

	@Autowired
	private BdZxInfoDao bdZxInfoDao;

   	/**
	 * 新增数据 
     * @param inBdZxInfoVo
     * @return 
	 */
	public int insertBdZxInfo(BdZxInfoVO inBdZxInfoVo) {
		logger.debug("当前新增数据为:"+ inBdZxInfoVo.toString());
		int num = 0;
		try {
			BdZxInfo bdZxInfo = new BdZxInfo();
			beanCopy(inBdZxInfoVo, bdZxInfo);
			num = bdZxInfoDao.insertBdZxInfo(bdZxInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inBdZxInfoVo
 	 * @return
	 */
	public int deleteByPk(BdZxInfoVO inBdZxInfoVo) {
		logger.debug("当前删除数据条件为:"+ inBdZxInfoVo);
		int num = 0;
		try {
			BdZxInfo bdZxInfo = new BdZxInfo();
			beanCopy(inBdZxInfoVo, bdZxInfo);
			num = bdZxInfoDao.deleteByPk(bdZxInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBdZxInfoVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inBdZxInfoVo
	 * @return 
	 */  
	public int updateByPk(BdZxInfoVO inBdZxInfoVo) {
		logger.debug("当前修改数据为:"+ inBdZxInfoVo.toString());
		int num = 0;
		try {
			BdZxInfo bdZxInfo = new BdZxInfo();
			beanCopy(inBdZxInfoVo, bdZxInfo);
			num = bdZxInfoDao.updateByPk(bdZxInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inBdZxInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param bdZxInfo
	 * @return 
	 */
	public BdZxInfoVO queryByPk(BdZxInfoVO inBdZxInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inBdZxInfoVo);
		try {
			BdZxInfo queryBdZxInfo = new BdZxInfo();
			beanCopy(inBdZxInfoVo, queryBdZxInfo);
			BdZxInfo queryRslBdZxInfo = bdZxInfoDao.queryByPk(queryBdZxInfo);
			if (Objects.nonNull(queryRslBdZxInfo)) {
				BdZxInfoVO outBdZxInfoVo = beanCopy(queryRslBdZxInfo, new BdZxInfoVO());
				logger.debug("当前查询结果为:"+ outBdZxInfoVo.toString());
				return outBdZxInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param bdZxInfo
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<BdZxInfoVO> queryAllByLevelOne(BdZxInfoVO bdZxInfoVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<BdZxInfoVO> list = null;
		try {
			List<BdZxInfo> bdZxInfos = bdZxInfoDao.queryAllByLevelOneByPage(bdZxInfoVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ bdZxInfos.size());
			pageSet(bdZxInfos, bdZxInfoVo);
			list = (List<BdZxInfoVO>) beansCopy(bdZxInfos, BdZxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param bdZxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<BdZxInfoVO> queryAllByLevelTwo(BdZxInfoVO bdZxInfoVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<BdZxInfo> bdZxInfos = bdZxInfoDao.queryAllByLevelTwoByPage(bdZxInfoVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+bdZxInfos.size());
		List<BdZxInfoVO> list = null;
		try {
			pageSet(bdZxInfos, bdZxInfoVo);
			list = (List<BdZxInfoVO>) beansCopy(bdZxInfos, BdZxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param bdZxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<BdZxInfoVO> queryAllByLevelThree(BdZxInfoVO bdZxInfoVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<BdZxInfo> bdZxInfos = bdZxInfoDao.queryAllByLevelThreeByPage(bdZxInfoVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ bdZxInfos.size());
		List<BdZxInfoVO> list = null;
		try {
			pageSet(bdZxInfos, bdZxInfoVo);
			list = (List<BdZxInfoVO>) beansCopy(bdZxInfos, BdZxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param bdZxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<BdZxInfoVO> queryAllByLevelFour(BdZxInfoVO bdZxInfoVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<BdZxInfo> bdZxInfos = bdZxInfoDao.queryAllByLevelFourByPage(bdZxInfoVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ bdZxInfos.size());
		List<BdZxInfoVO> list = null;
		try {
			pageSet(bdZxInfos, bdZxInfoVo);
			list = (List<BdZxInfoVO>) beansCopy(bdZxInfos, BdZxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param bdZxInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<BdZxInfoVO> queryAllByLevelFive(BdZxInfoVO bdZxInfoVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<BdZxInfo> bdZxInfos = bdZxInfoDao.queryAllByLevelFiveByPage(bdZxInfoVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ bdZxInfos.size());
		List<BdZxInfoVO> list = null;
		try {
			pageSet(bdZxInfos, bdZxInfoVo);
			list = (List<BdZxInfoVO>) beansCopy(bdZxInfos, BdZxInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
}
